@extends('admin.layout.app')
@section('title', '用户管理')

@section('nav')
    @include('admin.layout.nav', ['title'=> ['系统管理','编辑用户']])
@endsection

@section('content')
    <div class="box box-primary" style="min-height: 300px;">
        <div class="box-header with-border">
            <h3 class="box-title">编辑用户</h3>
        </div>
        <!-- /.box-header -->
        <form action="" method="post" id="add-form">
            {{ csrf_field() }}
            <div class="box-body">
                <input type="text" value="{{$user->id}}" name="id" style="display: none;" />
                <div class="form-group">
                    <label for="username">用户名：</label>
                    <input type="text" class="form-control" name="username" value="{{$user->name}}" placeholder="">
                    @if($errors->has('username'))
                        <label class="control-label" for="inputError1">{{$errors->first('username')}}</label>
                    @endif
                </div>
                <div class="form-group">
                    <label for="email">邮箱：</label>
                    <input type="email" class="form-control" name="email" value="{{$user->email}}"  placeholder="">
                    @if($errors->has('email'))
                        <label class="control-label" for="inputError1">{{$errors->first('email')}}</label>
                    @endif
                </div>
                <div class="form-group">
                    <label for="email">是否禁用：</label>
                    <div class="radio">
                        <label>
                            <input type="radio" name="status" value="1" @if($user->status==1)checked @endif>
                            启用
                        </label>
                        <label>
                            <input type="radio" name="status"  value="0" @if($user->status==0)checked @endif>
                            禁用
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    {{--<label for="description">角色：</label>--}}
                    <select multiple="multiple" class="form-control" name="roles-assign[]">
                        @foreach($roles as $role)
                            <option value="{{$role->id}}" @if($role->selected) selected @endif>{{$role->display_name}}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <!-- /.box-body -->

            <div class="box-footer">
                <input type="submit" class="btn btn-primary" value="提交">
                <a class="btn btn-default pull-right" href="javascript:window.history.back();">返回</a>
            </div>
        </form>

    </div>
@endsection

@section('style')
    <link rel="stylesheet" href="/lib/jquery.validation/1.14.0/validation.css">
    <link rel="stylesheet" href="/AdminLTE-2.4.2/plugins/duallistbox-bootstrap/bootstrap-duallistbox.min.css" />
    <style>

    </style>
@endsection

@section('js')
    <script type="text/javascript" src="/AdminLTE-2.4.2/plugins/duallistbox-bootstrap/jquery.bootstrap-duallistbox.min.js"></script>
    <script type="text/javascript" src="/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript" src="/lib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="/lib/jquery.validation/1.14.0/messages_zh.js"></script>
    <script>
        var demo1 = $('select[name="roles-assign[]"]').bootstrapDualListbox({
            nonSelectedListLabel: '可分配角色',
            selectedListLabel: '已分配角色',
            moveOnSelect: false,
        });
        $(function(){
            $("#add-form").validate({
                rules: {
                    username: {
                        required: true,
                        minlength: 2
                    },
                    email: {
                        required: true,
                        email:true
                    }
                },
                messages: {
                    username: {
                        required: "请输入用户名",
                        minlength: "用户名必需由两个字母组成",
                        maxlength: '用户名不能超过50个字符'
                    },
                    email:{
                        required: "请输入邮箱",
                        email: "您输入的邮箱格式不正确"
                    }
                },
                errorPlacement: function(error, element) {
                    error.appendTo(element.parent());
                }
            })
        })
    </script>
@endsection